package com.xfatm.killer.util;

import android.app.Activity;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wenjie on 2018/3/24.
 */

public class Activitys {
    private static Map<String,Activity> activityMap=new HashMap<>();
    private static Activity topActivity;

    public static void add(Activity a){
        activityMap.put(a.getClass().getName(),a);
    }

    public static void destory(Activity a){
        activityMap.remove(a.getClass().getName());
    }

    public static void setTopAndAdd(Activity a){
        topActivity=a;
        add(a);
    }

    public static void finish(Activity a){
        destory(a);
        a.finish();
    }

    public static Activity top(){
        return topActivity;
    }

    public static void finishAll(){
        for(Activity a:activityMap.values()){
            if(a.getClass().getName().equals(topActivity.getClass())){
                continue;
            }
            a.finish();
        }
        topActivity.finish();
    }
}
